home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT10 / PRINLOW.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  3.7 KB  |  82 lines

  1. ;****************************************************************
  2. ;  Program PrinLow ( Chapter 10 )
  3. ;
  4. ;  The program for outputting text string onto the printer
  5. ;
  6. ;  Author: A.I.Sopin, Voronezh, Russia,  1991
  7. ;
  8. ;  The LPT registers programming is used
  9. ;
  10. ;****************************************************************
  11. ;----------------------------------------------------------
  12. .MODEL SMALL
  13. .STACK
  14. .DATA
  15. CR       EQU    13      ;  Carriage Return   
  16. LF       EQU    10      ;  Line  Feed
  17. LPT1     DW     0
  18. MSG1     DB     ' Output string onto the printer (low-level technique) '
  19.      DB     CR, LF
  20. LMSG1    EQU    $-MSG1
  21. MSG2     DB     13,10, 'Error while outputting the string !!!',13,10,'$'
  22. MSG3     DB     13,10, 'Printer not ready !!!',13,10,'$'
  23. MSG4     DB     13,10, 'Error during printer initialisation !!!',13,10,'$'
  24. ;----------------------------------------------------------
  25. .CODE
  26. .startup
  27. ;--- Check the printer status register
  28.      mov    ax,40h          ;  segment address of BIOS data area
  29.      mov    ES,ax           ;  ES points to BIOS data area
  30.      mov    dx,ES:[8]       ;  address of LPT1 port into DX
  31.      mov    LPT1,dx         ;  store LPT1 address into memory
  32.      inc    dx              ;  address of printer status register into DX
  33.      in     al,dx           ;  get printer status
  34.      jmp    $+2             ;  this is needed for fast PC
  35.      test   al,80h
  36.      jnz    Init            ;
  37.      lea    dx,MSG3         ;  addres of error message into DS:DX
  38.      jmp    Text            ;  output error message and exit
  39. ;--- Initialise the printer port
  40. Init:    mov    dx,LPT1         ;  address of LPT1 port into DX
  41.      add    dx,2            ;  address of control register
  42.      mov    al,0Ch          ;  value 0Ch is initial code
  43.      out    dx,al           ;  initialisation
  44.      mov    cx,3000         ;  number of dummy cycles for delay
  45.      loop   $               ;  empty cycle (delay)
  46.      mov    al,08h          ;  value for initialisation completion
  47.      out    dx,al           ;  complete initialisation
  48. ;----------------------------------------------------------
  49. ;--- Send the ASCII - string onto the printer
  50. Print:   mov    cx,LMSG1        ;  length of string to be output
  51.      lea    si,MSG1         ;  DS:SI - address of string
  52.      cld                    ;  direction - forward!
  53. ;  send a character onto printer
  54. Next:    lodsb                  ;  load character into AL
  55.      mov    dx,LPT1         ;  address of LPT1 port into DX
  56.      out    dx,al           ;  send one character onto printer
  57.      inc    dx              ;
  58.      inc    dx              ;  address of control register
  59.      mov    al,0Dh          ;  value for strobe impulse  
  60.      out    dx,al           ;  send strobe 
  61.      dec    al              ;  normal state of register 
  62.      out    dx,al           ;  switch strobe off
  63. ;  Testing result of the operation     
  64.      dec    dx              ;  state register address 
  65.      in     al,dx           ;  read state register
  66.      test   al,08h          ;  printer error ?
  67.      jz     Error           ;  output error message
  68. ;  Waiting for release of printer
  69. Wait0:   in     al,dx           ;  read status register
  70.      test   al,80h          ;  is printer busy?
  71.      jz     Wait0           ;  if so, wait
  72.      loop   Next            ;  if not, process next character
  73.      jmp    Exit            ;  exit program
  74. Error:   lea    dx,MSG2         ;  address of error message into DS:DX
  75. ;----------------------------------------------------------
  76. ;--- Exit at successful finish of printing or at error
  77. Text:    mov    ah,9            ;  function 09h - output text string
  78.      int    21h             ;  DOS service call
  79. Exit:    mov    ax,4C00h        ;  Return Code = 0
  80.      int    21h             ;  Return to  MS-DOS
  81.      END
  82.